package com.aatrox.bhsypro.controller;

import com.aatrox.bhsypro.entity.BUser;
import com.aatrox.bhsypro.entity.BhSyGos;
import com.aatrox.bhsypro.service.BUserService;
import com.aatrox.bhsypro.service.BhSyGosService;
import com.aatrox.bhsypro.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@RestController
public class BhSyGosAjaxController {

    @Autowired
    BhSyGosService bgs;
    @Autowired
    BUserService bus;

    @RequestMapping(value = "/Gos/sq/{uid}",method = RequestMethod.POST)
    public JsonResult GosSq(@PathVariable("uid") int uid){
        bgs.insertNewGos(uid);
        return new JsonResult(200,"添加成功",null);
    }

    @RequestMapping(value = "/Gos/ag/{guid}",method = RequestMethod.PUT)
    public JsonResult gosAng(@PathVariable("guid") int guid){
        HashMap hm = new HashMap();
        bgs.updateBeGos(guid);
        List<BhSyGos> list = bgs.selAllGos();
        List<BUser> list1 = new ArrayList<>();
        for (BhSyGos bsg : list){
            list1.add(bus.selUserForUid(bsg.getUid()));
        }
        hm.put("GosUser",list1);
        return new JsonResult(200,"成功",hm);
    }
}
